<?php $aRole = unserialize(ROLE_NAME); $folder = $this->input->get('f', true); ?>

<div class="row">
    <div class="col-md-12">
        <h1>Rao vặt <small>Danh sách tin rao vặt</small></h1>
        <ol class="breadcrumb">
            <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="<?php echo admin_page_url(RAOVAT_SLUG); ?>"><i class="fa fa-table"></i> Rao vặt</a></li>
        </ol>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-xs-12">
        <form method="get" action="<?php echo admin_page_url(RAOVAT_SLUG.'/tim-kiem'); ?>" enctype="multipart/form-data">
            <div class="input-group">
                <input type="text" class="form-control" name="s" value="<?php echo isset($searchkey)?$searchkey:''; ?>" placeholder="Tìm kiếm" />
                <span class="input-group-btn">
                    <button class="btn btn-success" type="submit"><i class="fa fa-search"></i> Tìm kiếm!</button>
                </span>
            </div><!-- /input-group -->
        </form>
    </div>

    <div class="col-md-6 col-xs-12">
        <p class="pull-right">
            <a class="btn btn-success" href="<?php echo admin_page_url(RAOVAT_SLUG.'/them'); ?>">
                <i class='glyphicon glyphicon-plus-sign'></i> Thêm tin mới
            </a>
            <a class="btn btn-success" href="<?php echo admin_page_url(RAOVAT_SLUG.'/'.RAOVAT_HIGHLIGHT_SLUG); ?>">
                <i class="fa fa-star"></i> Nổi bật
            </a>
            <?php
            $page_link = '';
            $page_text = '';
            if($folder!='trash'){
                $page_link = admin_page_url(RAOVAT_SLUG, array('f'=>'trash'));
                $page_text = '<i class="fa fa-trash-o"></i> Không hiển thị';
            } else {
                $page_link = admin_page_url(RAOVAT_SLUG);
                $page_text = '<i class="fa fa-check-circle"></i> Hiển thị';
            }
            ?>
            <a class="btn btn-default" href="<?php echo $page_link; ?>"><?php echo $page_text; ?></a>
        </p>
    </div>
    <div class="clearfix"></div>

    <div class="col-md-12 col-xs-12">
        <?php echo $pagingBar; ?>
    </div>
</div>

<div class="row mgt5">
    <div class="col-md-12">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter item-list" data-href='<?php echo admin_page_url(RAOVAT_SLUG.'/'.UPDATE_SLUG); ?>'>
                <thead>
                    <tr>
                        <th class="header"># <i class="fa fa-sort"></i></th>
                        <th class="header">Hình ảnh</th>
                        <th class="header">Thông tin <i class="fa fa-sort"></i></th>
                        <th class="header">Mô tả <i class="fa fa-sort"></i></th>
                        <th class="header">&nbsp;</th>
                    </tr>
                    <tr class="tr-temp hidden warning">
                        <td colspan="8">
                            <form role="form" method="post" action="<?php echo admin_page_url(RAOVAT_SLUG.'/'.UPDATE_SLUG); ?>" data-callback='1'>
                                <div class="col-md-6 col-xs-12">
                                    <div class="form-group">
                                        <label for="input-raovat-title">Tiêu đề</label>
                                        <input type="text" class="form-control auto-slug" follow-ctr='#input-raovat-slug' id="input-raovat-title" name="raovat[title]" value="" />
                                    </div>
                                    <div class="form-group">
                                        <label for="input-raovat-slug">Đường dẫn</label>
                                        <input type="text" class="form-control" id="input-raovat-slug" name="raovat[slug]" value="" />
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-8 col-xs-6">
                                            <label for="input-raovat-cate">Danh mục</label>
                                            <select class="form-control" id="input-raovat-cate" name="raovat[cate_id]">
                                                <?php foreach($aParentCate as $pCate) { ?>
                                                <option value="<?php echo $pCate->getId(); ?>">
                                                    <?php echo $pCate->getTitle(); ?>
                                                </option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                        <div class="form-group col-md-4 col-xs-6">
                                            <label for="input-raovat-place">Nơi áp dụng</label>
                                            <select class="form-control" id="input-raovat-place" name="raovat[place_id]">
                                                <?php foreach($aRaoVatPlace as $pl) { ?>
                                                <option value="<?php echo $pl->getId(); ?>">
                                                    <?php echo $pl->getName(); ?>
                                                </option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6 col-xs-6">
                                    <div class="form-group">
                                        <label for="input-raovat-description">Mô tả</label>
                                        <textarea class="form-control" id="input-raovat-description" name="raovat[description]"></textarea>
                                    </div>

                                    <div class="checkbox">
                                        <label for="input-raovat-active-flg">
                                            <input type="checkbox" id="input-raovat-active-flg" name="raovat[active_flg]" value="1"/> Hiển thị
                                        </label>
                                    </div>

                                    <div class="checkbox">
                                        <label for="input-raovat-highlight-flg">
                                            <input type="checkbox" id="input-raovat-highlight-flg" name="raovat[highlight_flg]" value="1"/> Nổi bật
                                        </label>
                                    </div>

                                    <div class="checkbox">
                                        <label for="input-raovat-delete-flg">
                                            <input type="checkbox" id="input-raovat-delete-flg" name="raovat[delete_flg]" value="1"/> Xoá
                                        </label>
                                    </div>

                                    <div>
                                        <input type="hidden" name="raovat[update_case]" value="<?php echo UPDATE_FULL; ?>" />
                                        <input type="hidden" name="raovat[id]" id="input-raovat-id" />
                                        <button type="button" class="btn btn-success btn-submit-update">
                                            <i class="glyphicon glyphicon-ok-sign"></i> Cập nhật
                                        </button>
                                        <button type="button" class="btn btn-danger btn-cancel-update">
                                            <i class="glyphicon glyphicon-remove-sign"></i>  Huỷ
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($aRaoVat as $index=>$r) { ?>
                    <tr class="input-raovat-info can-edit" data-id="<?php echo $this->encrypt->encode($r->getId()); ?>">
                        <th class="header bg-info"><?php echo $index+1; ?></th>
                        <td class="col-md-3 input-raovat-img">
                            <a class="thumbnail" href="<?php echo admin_raovat_single_url($r->getSlug()); ?>" title="<?php echo $r->getTitle(); ?>">
                                <?php if($r->getImage()!=null && image_exist('public/' . $r->image_folder.'/'.RAOVAT_IMAGE_URL.$r->getImage())) { ?>
                                <img class="has-border" src="<?php echo raovat_upload($r->getImage(), $r->image_folder); ?>" />
                                <?php } else { ?>
                                <img class="has-border" data-src="holder.js/96x96/text:Hình đại diện" />
                                <?php } ?>
                            </a>
                        </td>
                        <td>
                            <h4>
                                <a class="input-raovat-title strong big-title" href="<?php echo admin_raovat_single_url($r->getSlug()); ?>">
                                    <?php echo $r->getTitle(); ?>
                                </a>
                            </h4>
                            <h4>
                                <a class="input-raovat-cate" data-id="<?php echo $r->getCateId(); ?>" target="_blank" href="<?php echo category_url($r->cate_slug); ?>">
                                    <label class="label label-danger"><?php echo $r->cate_title; ?></label>
                                </a>
                            </h4>
                            <p class="input-raovat-place" data-id="<?php echo $r->getPlaceId(); ?>"><?php echo $r->place_name; ?></p>
                            <p><?php echo $r->user_full_name; ?> ( <span class="<?php echo $r->role==ROLE_ADMIN?'admin':'mod'; ?>"><?php echo $aRole[$r->role]; ?></span> )</p>
                            <p><?php echo fdate_format($r->getCreatedAt()); ?></p>
                            <p class="strong"><?php echo $r->getViewTime(); ?></p>
                        </td>
                        <td class="w300 input-raovat-description"><?php echo $r->getDescription(); ?></td>
                        <td class="input-raovat-flg">
                            <p class="inline-table clearMgr">
                                Nổi bật
                                <input type="checkbox" class="checkbox lb-toggle" id="chk-highlight-<?php echo $index+1; ?>" data-name="highlight_flg"  value="1"
                                <?php echo $r->getHighlightFlg()==1 ?"checked='checked'":''; ?> />
                                <label for="chk-highlight-<?php echo $index+1; ?>"></label>
                            </p>
                            <p class="inline-table clearMgr">
                                Hiển thị
                                <input type="checkbox" class="checkbox lb-toggle" id="chk-active-<?php echo $index+1; ?>" data-name="active_flg"  value="1"
                                <?php echo $r->getActiveFlg()==1 ?"checked='checked'":''; ?> />
                                <label for="chk-active-<?php echo $index+1; ?>"></label>
                            </p>
                            <p class="inline-table clearMgr">
                                Xoá
                                <input type="checkbox" class="checkbox lb-toggle red" id="chk-delete-<?php echo $index+1; ?>" data-name="delete_flg"  value="1"
                                <?php echo $r->getDeletedAt()!=NULL ?"checked='checked'":''; ?> />
                                <label for="chk-delete-<?php echo $index+1; ?>"></label>
                            </p>
                            <div class="clearfix mgt5"></div>
                            <a class="btn btn-success input-raovat-slug mgt5" target="_blank" data-slug="<?php echo $r->getSlug(); ?>" href="<?php echo rao_vat_single_url($r->getSlug()); ?>">
                                <i class='glyphicon glyphicon-share-alt'></i> Xem
                            </a>
                            <a class="btn btn-primary input-raovat-update mgt5" href="<?php echo admin_raovat_single_url($r->getSlug()); ?>">
                                <i class='glyphicon glyphicon-pencil'></i> Cập nhật
                            </a>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="clearfix"></div>
</div>